# -*- coding:utf-8 -*-
# @FileName  :彼岸图网1.py
# @Time      :2022/5/31 7:03

import requests
from lxml import etree


def get_url(name):
    for i in range(1,2):
        if i == 1:
            url = f'https://pic.netbian.com/4k{name}/index.html'
        else:
            url = f'https://pic.netbian.com/4k{name}/index_{i}.html'
        html = requests.get(url)
        html.encoding = 'gbk'
        selector = etree.HTML(html.text)
        links = selector.xpath('//div[@class="slist"]/ul/li/a/img/@src')
        titles = selector.xpath('//div[@class="slist"]/ul/li/a/b/text()')
        links = ['https://pic.netbian.com' + i for i in links]
        i=1
        for title,link in zip(titles,links):
            download(title,link)
            print(f'正在下载第{i}张')
            i+=1


def download(title,url):
    #路径自己选择
    with open(f'D:\Download\image\{title}.jpg','wb') as f:
        data=requests.get(url).content
        f.write(data)

#输入下载壁纸分类的拼音
get_url('fengjing')